<template>
  <v-card :title="title" @submit="submit" @reset="reset">
    <v-form
      :form-title="formTitle"
      :form-data="formData"
      label-width="120px"
    />
  </v-card>
</template>

<script>
export default {
  name:'miniprogram',
  props: {
    type: {
      type: String,
      default: () => ''
    }
  },
  data() {
    return {
      title: '编辑',
      formData: {

      },
      tencentList: [],

    }
  },
  computed:{
    formTitle(){
      return ([
        {
          cn: 'id',
          en: 'fansid',
          disabled: true
        },
        {
          cn: '角色名称',
          en: 'fansname',
          disabled: true
        },
        {
          cn: '所属公司',
          en: 'conpaniesname',
          disabled: true
        },
        {
          cn: '公众号',
          en: 'mp_ids',
          type:'checkbox',
          list:this.tencentList,
        },
        {
          cn: '描述',
          en: 'desc',
          type: 'textarea',
          disabled: true
        },
        {
          cn: '创建时间',
          en: 'created_at',
          disabled: true
        },
        {
          cn: '修改时间',
          en: 'updated_at',
          disabled: true
        }
      ])
    }
  },
  activated() {
    this.formData = JSON.parse(this.$route.query.details)

    this.$emit('childTitle', this.$route.meta.title1)
    this.getTencentList()
  },

  methods: {
    // 撤销
    reset() {
      this.formData = JSON.parse(this.$route.query.details)
      this.formData.mp_ids = this.formData.mp_ids.split(',').map(item=>{
        return Number(item)
      })
    },

    // 获取公众号列表
    getTencentList() {
      this.$get('action/WechatNumber/tree')
        .then(res => {
          const list = []
          if (res.data.WechatTree) {
            res.data.WechatTree.forEach(item => {
              list.push({
                label: item.name,
                value: item.id
              })
            })
          }
          this.tencentList = list
          // 接收传参
          this.formData.mp_ids = this.formData.mp_ids.split(',').map(item=>{
            return Number(item)
          })
        })
        .catch(_ => console.log(1))
    },

    submit() {
      const data = this.$deepClone(this.formData)
      data.mp_ids = data.mp_ids.join(',')
      this.$post('action/WxUserCtrl/save', data)
        .then(res => {
          this.$message({
              message:res.msg,
              type:'success'
          })
          this.$router.go(-1)
        })
    }
  }
}
</script>

<style scoped>

</style>
